﻿using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {

        private void JLTVKQC(DataSet db)
        {
            try
            {
                DataTable tbVKPOS = db.Tables["VKPOS"];  
                DataTable dtOutput = new DataTable(); 
                dtOutput.Merge(tbVKPOS, false, MissingSchemaAction.Ignore);
                string ART = ""; string KD = ""; string DEL = ""; string ARTNAME = ""; string DESC = ""; int VON = 0; int BIS = 0;
                DataRow VKP=tbVKPOS.Rows[0];
                ART=VKP["VKPART"].ToString().Trim();
                KD = VKP["KDKNAME"].ToString().Trim();
                KD = GetGB2312Value(KD);
                DEL = VKP["VKPLIEFTERM"].ToString().Trim(); 
                ARTNAME = VKP["ARTNAME"].ToString().Trim();
                ARTNAME = GetGB2312Value(ARTNAME);
                DESC = VKP["DESCR"].ToString().Trim();
                DESC = GetGB2312Value(DESC);
                VON = Convert.ToInt32(VKP["VAABRTVON"].ToString().Trim())/100;
                VON=VON+1;
                BIS = Convert.ToInt32(VKP["VAABRTBIS"].ToString().Trim())/100;
                exAgent.SetCellValue(4,5,ART);
                exAgent.SetCellValue(4, 15, KD);
                exAgent.SetCellValue(4, 25, DEL.Substring(0,4)+"- "+DEL.Substring(4,2)+" -"+DEL.Substring(6,2));
                exAgent.SetCellValue(5, 5, ARTNAME);
                exAgent.SetCellValue(5, 20, DESC+"  "+VON+"/"+BIS);
                int i = 1; int j = 1; string FARBE = ""; string QTY = ""; string MEEH = ""; string AVGRATE = ""; 
                foreach (DataRow vkp in tbVKPOS.Rows)
                {
                    if(i<30)
                    {
                         FARBE = vkp["VKPFARBE"].ToString().Trim();  QTY = vkp["VKPMENGE1"].ToString().Trim();
                         MEEH = vkp["VKPMEEH"].ToString().Trim(); /*string AYARD = vkp["AYARD"].ToString().Trim(); string BYARN = vkp["BYARN"].ToString().Trim();*/
                         AVGRATE = vkp["AVGRATE"].ToString().Trim();
                        exAgent.SetCellValue(6, i + 4, FARBE);
                        exAgent.SetCellValue(7, i + 4, QTY + MEEH);
                        /*if (AYARD != "")
                        { 
                            exAgent.SetCellValue(8, i + 4, AYARD + MEEH);
                        }
                        if (BYARN != "")
                        {
                            exAgent.SetCellValue(9, i + 4, BYARN + MEEH);
                        }*/
                        if (AVGRATE != "")
                        {
                            exAgent.SetCellValue(12, i + 4, AVGRATE + "分/by2");
                        }
                        i = i + 5;
                    }
                    else 
                        {
                            FARBE = vkp["VKPFARBE"].ToString().Trim(); QTY = vkp["VKPMENGE1"].ToString().Trim();
                            MEEH = vkp["VKPMEEH"].ToString().Trim(); /*string AYARD = vkp["AYARD"].ToString().Trim(); string BYARN = vkp["BYARN"].ToString().Trim();*/
                            AVGRATE = vkp["AVGRATE"].ToString().Trim();
                            if (j == 1)
                            {
                                exAgent.RangeCopy(1, 28, 30, 57);
                                exAgent.SetCellValue(30, 1, "金陵纺织品质自检评定表");
                                exAgent.SetCellValue(32, 28, "编号：JL/QR-Z-C10");
                                exAgent.SetCellValue(33, 1, "任务书号");
                                exAgent.SetCellValue(33, 10, "客户");
                                exAgent.SetCellValue(33, 20, "交货日期");
                                exAgent.SetCellValue(34, 1, "产品名称");
                                exAgent.SetCellValue(34, 15, "规格");
                                exAgent.SetCellValue(35, 1, "花型号");
                                exAgent.SetCellValue(36, 1, "订单数量");
                                exAgent.SetCellValue(37, 1, "成品" + System.Environment.NewLine + System.Environment.NewLine + "数量");
                                exAgent.SetCellValue(37, 3, "一等");
                                exAgent.SetCellValue(38, 3, "样布");
                                exAgent.SetCellValue(39, 3, "二等");
                                exAgent.SetCellValue(40, 3, "余数");
                                exAgent.SetCellValue(41, 1, "外观评分");
                                exAgent.SetCellValue(42, 1, "颜色" + System.Environment.NewLine + System.Environment.NewLine + "(左右色差)");
                                exAgent.SetCellValue(44, 1, "格型" + System.Environment.NewLine + System.Environment.NewLine + "(左右格型)");
                                exAgent.SetCellValue(46, 1, "主要异常");
                                exAgent.SetCellValue(47, 1, "内在质量");
                                exAgent.SetCellValue(48, 1, "备注");
                                exAgent.SetCellValue(49, 1, "质检科意见：");
                                exAgent.SetCellValue(54, 1, "成品负责人：");
                                exAgent.SetCellValue(54, 13, "品管员：");
                                exAgent.SetCellValue(54, 27, "年");
                                exAgent.SetCellValue(54, 30, "月");
                                exAgent.SetCellValue(54, 33, "日");
                                exAgent.SetCellValue(55, 1, "分管领导意见：");
                                exAgent.SetCellValue(55, 25, "签名：");
                            } 
                            exAgent.SetCellValue(33, 5, ART);
                            exAgent.SetCellValue(33, 15, KD);
                            exAgent.SetCellValue(33, 25, DEL.Substring(0, 4) + "-" + DEL.Substring(4, 2) + "-" + DEL.Substring(6, 2));
                            exAgent.SetCellValue(34, 5, ARTNAME);
                            exAgent.SetCellValue(34, 20, DESC + "  " + VON + "/" + BIS);
                            exAgent.SetCellValue(35, j + 4, FARBE);
                            exAgent.SetCellValue(36, j + 4, QTY + MEEH);
                            if (AVGRATE != "")
                            {
                                exAgent.SetCellValue(41, j + 4, AVGRATE + "分/by2");
                            }
                            j = j + 5;
                        }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        } 
    }
}